package com.itheima.service.impl;

import com.itheima.domain.ClassPeopleSum;
import com.itheima.domain.JobOption;
import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentsMapper;
import com.itheima.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
@Slf4j

public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentsMapper studentsMapper;

// 职位数据
    @Override
    public JobOption empJobData() {
      List<Map<String,Object>> jobData= empMapper.empJobData();
        //利用stream流处理数据，提取集合中每个map的职位名称和职位数量
      List<Object> jobList= jobData.stream().map(map -> map.get("pos")).collect(Collectors.toList());
      List<Object> dataList= jobData.stream().map(map -> map.get("total")).toList();
        return new JobOption(jobList,dataList) ;
    }
//性别数据
    @Override
    public List<Map> empGenderData() {
        return  empMapper.empGenderData();
    }
//学历数据
    @Override
    public List<Map> studentDegreeData() {
        return empMapper.studentDegreeData();
    }
//班级人数
    @Override
    public ClassPeopleSum studentCountData() {
       List<Map<String,Object>> clazzPeopleSum= studentsMapper.studentCountData();
       List<Object> clazzList= clazzPeopleSum.stream().map(map -> map.get("clazzList")).toList();
       List<Object> dataList= clazzPeopleSum.stream().map(map -> map.get("dataList")).toList();
       return new ClassPeopleSum(clazzList,dataList);
    }
}
